<template>
  <div class="app-container">
    <el-form ref="form" :model="list" :rules="rules" label-width="120px">
      <el-form-item label="ID" hidden="hidden">
        <el-input v-model="list.id" />
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input v-model="list.userId" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="用户名" prop="userName">
        <el-input v-model="list.userName" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="密码" prop="passWord">
        <el-input v-model="list.passWord" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="真实姓名" prop="realName">
        <el-input v-model="list.realName" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="电话" prop="userPhone">
        <el-input v-model="list.userPhone" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="用户身份">
        <el-input v-model="list.userIdentity" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">确定</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import qs from 'qs'

export default {
  data() {
    return {
      list: {
        userId: '',
        userName: '',
        passWord: '',
        realName: '',
        userPhone: '',
        userIdentity: ''
      }
    }
  },
  methods: {

    onSubmit() {
      this.$axios.post(`user/addUser`, qs.stringify({
        'id': this.list.id,
        'userId': this.list.userId,
        'userName': this.list.userName,
        'passWord': this.list.passWord,
        'realName': this.list.realName,
        'userPhone': this.list.userPhone,
        'userIdentity': this.list.userIdentity
      }), {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
      })
        .then(res => {
          this.$message({
            message: '操作成功！',
            type: 'success'
          })
          this.$router.push('/example/user')
        })
    },
    onCancel() {
      this.$message({
        message: '取消成功！',
        type: 'warning'
      })
      this.$router.push('/example/user')
    }

  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

